<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

class JobBoardControllerJAProfiles extends JobBoardController{

    /**
     * Constructor
     */
    function __construct( $default = array() )
    {
    	$layout = JRequest::getVar('layout');
        if ($layout=='download')
        	JRequest::setVar('task','download');
        parent::__construct( $default );
        $this->set('name', 'profiles');
        $this->set('fullname', 'japrofiles');
        
        // Register Extra tasks
        $this->registerTask( 'add',        'edit' );
        $this->registerTask( 'apply',    'save' );
        $this->registerTask( 'inactivate',    'activate' );
    }
    
    /**
    * Display current configuration of the component to administrator
    * 
    */
    function display(){	
    	$user = JFactory::getUser();
//        if ($user->id==0)
//        {
//        	$this->setRedirect(JRoute::_("index.php?option=com_user&view=login"));
//        	return ;
//        }	
		parent::display();
    }
    
    /**
    * Cancel current operation
    * 
    */
    function cancel(){
    	$user = JFactory::getUser();
        $Itemid = JRequest::getVar('Itemid');
        $limited = JRequest::getVar('limited', 1);
        if (($user->usertype!='Administrator')&&($user->usertype!='Super Administrator')) 
        	$this->setRedirect(JRoute::_("index.php?option=". JBCOMNAME ."&view=". $this->get('fullname')."&limited=".$limited."&Itemid=".$Itemid));
        else 	
        	$this->setRedirect( JRoute::_('index.php?option='. JBCOMNAME .'&view=jaemployers'));
    }
    
    /**
    * Remove a configuration row
    * 
    */
    function remove(){
    	// Check for request forgeries
		// Check for request forgeries
        if(!JRequest::checkToken()){
            JResponse::setHeader('HTTP/1.0 403',true);
            JError::raiseWarning( 403, JText::_("Access denied. You don't have permission.") ); 
            echo "<a href='javascript:window.history.go(-1);'>". JText::_('Back')."</a>"; 
            return;
        }
        $task = JRequest::getVar('task', 'remove');
        $model =& $this->getModel(JBPREFIX.'profiles');
        $n = $model->remove($task);
		$Itemid = JRequest::getVar('Itemid');
//        $limited = JRequest::getVar('limited', 0);
        		
		$this->setMessage(JText::_('Successfully delete resume!'));
		$this->setRedirect(JRoute::_('index.php?option='. JBCOMNAME .'&view='.$this->get('fullname').'&layout=jaview&Itemid='.$Itemid));
	}
	
	function activate(){
    	// Check for request forgeries
		JRequest::checkToken() or jexit( 'Invalid Token' );
        $Itemid = JRequest::getVar('Itemid');
        $model =& $this->getModel($this->get('fullname'));
        $task = JRequest::getVar('task', 'approved');
        $model->activate($task);
		$this->setRedirect('index.php?option='. JBCOMNAME .'&view='.$this->get('fullname')."&Itemid=".$Itemid);
	}
    
    /**
    * Edit forms
    */
    function edit($postback = false){
    	JRequest::setVar('postback',$postback);
        JRequest::setVar('edit', true);
        JRequest::setVar('layout','jaform');
        parent::display();
    }
    
    /**
    * View forms
    */
    /*function view(){
        JRequest::setVar('view', true);
        $model = & $this->getModel($this->get('fullname'));
        // $model->increaseViews();

        $view = & $this->getView($this->get('fullname'), 'html');
        $view->setModel($model, true);
		$view->setLayout(JBPREFIX."view");
        $view->view();
    }*/
	
	/**
	* Save configuration record
	*/
	function save(){
		// Check for request 
		$cid = JRequest::getVar( 'cid', array(0), '', 'array' );
		$userdetail = JRequest::getVar('userdetail');
		$user = JFactory::getUser();
		
		$step = JRequest::getVar('step', ''); 
        ($step == 'done') or JRequest::checkToken() or jexit( 'Invalid Token' );
        
        $Itemid = JRequest::getVar('Itemid');                        
        
        $model    =& $this->getModel('japrofiles');
        
        $rc = $model->store();
        if($rc){        	
        	 if ((isset($cid[0]))&&$cid[0]!=0)	
        		$msg = JText::_( 'Successfully updated your profile!' );   
        	else 
        		$msg = JText::_( 'Successfully created your profile!' ); 
             $this->setRedirect( JRoute::_('index.php?option='. JBCOMNAME .'&view=japrofiles&layout=jaview&Itemid='.$Itemid), $msg );
        } else {
//            JError::raiseWarning(0, JText::_('There are some invalid data. Please check again'));
            $this->edit(true);
        }
	}
    
    function download(){
         $model    =& $this->getModel( $this->get('fullname') );    
         $model->download();
         exit;  
    }
    
    function remove_attach()
    {
    	$model    =& $this->getModel( 'japrofiles' );
    	$model->remove_attach();
         exit;
    }
}
?>